package com.taobao.search.controller;


import com.taobao.base.model.RestResponse;
import com.taobao.search.model.dto.GoodsDetailsDto;
import com.taobao.search.model.dto.GoodsPreviewDto1;
import com.taobao.search.model.po.Goods;
import com.taobao.search.srevice.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class GoodsController {

    @Autowired
    private GoodsService goodsService;


    // 测试
    @GetMapping("/test/{goodsId}")
    public RestResponse<String> test(@PathVariable("goodsId") int goodsId) {
        System.err.println(goodsId);
        return RestResponse.success("ss");
    }

    /**
     * 添加文档
     */
    @PostMapping("/addDoc")
    public RestResponse<String> addDoc(@RequestBody Goods goods) {
        RestResponse<String> stringRestResponse = goodsService.addDoc(goods);

        return stringRestResponse;
    }

    /**
     * 删除文档
     */
    @DeleteMapping("/deleteDoc/{goodsId}")
    public RestResponse<String> deleteDoc(@PathVariable("goodsId") Integer goodsId) {

        RestResponse<String> stringRestResponse = goodsService.deleteDoc(goodsId);
        return stringRestResponse;
    }

    /**
     * 查询文档
     */
    @GetMapping("/searchDoc/{id}")
    public RestResponse<Goods> searchDoc(@PathVariable("id") String id) {
        System.err.println(id);
        RestResponse<Goods> goodsRestResponse = goodsService.searchDoc(id);
        return goodsRestResponse;
    }

    /**
     * 局部更新
     */
    @PostMapping("/UpdateById")
    public RestResponse<String> UpdateById(@RequestBody Goods goods) {
        RestResponse<String> stringRestResponse = goodsService.UpdateById(goods);
        return stringRestResponse;
    }

    /**
     * 商品详情
     * 匹配查询
     */
    @GetMapping("/searchByTitle/{title}")
    public RestResponse<List<GoodsDetailsDto>> goodsDetailsByTitle(@PathVariable("title") String title) {
        System.out.println(title);
        RestResponse<List<GoodsDetailsDto>> listRestResponse = goodsService.goodsDetailsByTitle(title);
        return listRestResponse;
    }

    /**
     * 根据title查询搜素结果页商品
     */
    @GetMapping("/getGoodsPreviewByTitle/{title}")
    RestResponse<List<GoodsPreviewDto1>> getGoodsPreviewByTitle(@PathVariable("title") String title) {
        System.out.println(title);
        RestResponse<List<GoodsPreviewDto1>> listRestResponse = goodsService.getGoodsPreviewByTitle(title);
        return listRestResponse;
    }

}
